import pprint
import mysql.connector


def select(sql, values):
    # 打开数据库连接
    db_mysql = mysql.connector.connect(
        host="数据库地址",
        port=3306,
        user="用户名",
        password="用户密码"
    )
    # 使用 cursor()方法创建一个游标对象 cursor
    cursor = db_mysql.cursor()
    # cursor = cursor.cursor(pymysql.cursors.DictCursor)  # 转成字典
    cursor.execute(sql, values)
    # 记录所有获取的记录
    result = cursor.fetchall()
    # 得到域的名字
    cols = cursor.description
    col = []
    for i in result:
        row = {}
        for j in range(len(cols)-1):
            row[cols[j][0]] = i[j]
        col.append(row)
    coll = col
    cursor.close()
    db_mysql.close()
    return coll

